import threading


def foo():
    lock1.acquire()
    print('foo acquire lock1')
    lock2.acquire()
    print('foo acquire lock2')
    lock1.release()
    lock2.release()


def bar():
    lock2.acquire()
    print('bar acquire lock2')
    lock1.acquire()
    print('bar acquire lock1')
    lock2.release()
    lock1.release()


lock1 = threading.Lock()
lock2 = threading.Lock()

if __name__ == '__main__':
    t1 = threading.Thread(target=foo)
    t2 = threading.Thread(target=bar)
    t1.start()
    t2.start()
    t1.join()
    t2.join()

"""
上面的代码，偶发死锁
死锁指的是两个或者多个线程，相互等待对方释放所占用的资源而无法继续执行下去的情况。
"""